package com.tarena.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.tarena.dao.FilesDao;
import com.tarena.domain.Files;

/**
 * 图片显示
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-2-2
 */
public class SeePicServlet implements Servlet {

	public void destroy() {

	}

	public ServletConfig getServletConfig() {
		return null;
	}

	public String getServletInfo() {
		return null;
	}

	public void init(ServletConfig arg0) throws ServletException {

	}

	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<head>" + "<title>Infomation...</title>" + "</head>");
		out.println("<body>");
		out.println("<h1>预览图片</h1>");
		List<Files> list = new FilesDao().getFiles();

		for (Files f : list) {
			String src = f.getPath() + "/" + f.getName();
			System.out.println(f.getDescription());
			out.println("<span >");
			out.println("<img src='" + src + "' /><br>");
			out.println("对这张图片的描述:" + (f.getDescription()) + "<br>");
			out.println("</span>");
		}
		out.println("</body>");
		out.println("</html>");
	}

}
